import numpy as np

from ch3.forward import softmax
from ch4.loss_function import cross_entropy_error
from ch4.numerical_diff import numerical_gradient


class simpleNet:
    def __init__(self):
        # 使用高斯分布初始化
        self.W = np.random.randn(2, 3)

    def predict(self, x):
        return np.dot(x, self.W)

    def loss(self, x, t):
        z = self.predict(x)
        y = softmax(z)
        loss = cross_entropy_error(y, t)
        return loss


if __name__ == '__main__':
    net = simpleNet()
    x = np.array([0.6, 0.9])  # 1*2
    # p = net.predict(x)  # 1*2 2*3 =1*3
    # print(p)
    # print(np.argmax(p))
    t = np.array([0, 0, 1])
    f = lambda w: net.loss(x, t)  # 损失函数，返回的是一个数
    dW = numerical_gradient(f, net.W)
    print(dW)
